
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>添加用户 - BsAdmin后台模板 - 经典版演示</title>
    <link rel="icon" href="static/favicon.ico">
    <link rel="stylesheet" href="static/bootstrap/css/bootstrap.min.css" >
    <link rel="stylesheet" href="static/admin/css/index.css" >
    <link rel="stylesheet" href="static/admin/css/main.css" >
    <link rel="stylesheet" href="static/admin/css/html.css" >
    <script src="static/js/vue.min.js"></script>
    <script src="static/js/jquery-3.3.1.min.js" ></script>
    <script src="static/bootstrap/js/bootstrap.bundle.js" ></script>
    <script src="static/admin/js/script.js" ></script>
    <script>
        $(function () {
            let hrefArr = window.location.href.split('/');
            let name = hrefArr[hrefArr.length-1];
            $(".menu a[href='"+name+"']").addClass('active');
        })
    </script>
</head>
<body>

<div id="app" class="d-flex">

    <nav>
        <div class="logo">
            <h4>学生管理系统</h4>
        </div>
        <ul class="menu">
            <li><a href="main.html">
                <i class="iconfont mr-1">&#xe6a2;</i>首页</a>
            </li>
            <li><a class="top-menu" href="javascript:;">
                <i class="iconfont mr-1">&#xe6e0;</i>用户管理<i class="iconfont arrow float-right">&#xe66c;</i>
            </a>
                <ul class="sub-menu">
                    <li><a href="user_index.html" >用户列表</a></li>
                    <li><a href="user_create.html" >添加用户</a></li>
                </ul>
        </ul>
    </nav>

    <main>
        <header>
            <a href="http://www.qadmin.net" target="_blank">网站首页</a>

            <div class="dropdown float-right">
                <button class="btn  btn-sm  dropdown-toggle" type="button" id="dropdownMenu2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    <svg width="20" height="1em" viewBox="0 0 16 16" class="bi bi-emoji-smile-fill rounded-circle" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
                        <path fill-rule="evenodd" d="M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16zM7 6.5C7 7.328 6.552 8 6 8s-1-.672-1-1.5S5.448 5 6 5s1 .672 1 1.5zM4.285 9.567a.5.5 0 0 1 .683.183A3.498 3.498 0 0 0 8 11.5a3.498 3.498 0 0 0 3.032-1.75.5.5 0 1 1 .866.5A4.498 4.498 0 0 1 8 12.5a4.498 4.498 0 0 1-3.898-2.25.5.5 0 0 1 .183-.683zM10 8c.552 0 1-.672 1-1.5S10.552 5 10 5s-1 .672-1 1.5S9.448 8 10 8z"/>
                    </svg>
                    <!--可以使用图片,大小20,class='rounded-circle'-->
                    学生管理系统
                </button>

                <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenu2">
                    <a class="dropdown-item" href="repwd.html">修改密码</a>
                    <a class="dropdown-item" href="out.html">退出登录</a>
                </div>
            </div>

        </header>

        <div id="body">
            

<main>
    <div class="main">

        <div class="title-box">
            <h5>新增用户</h5>
        </div>
        <div class="form-box">
            <div class="row">
                <div class="col-5">
                    <form id="form">
                        <input id="id" name="id" type="hidden"/>
                        <div class="form-group">
                            <label>姓名</label>
                            <input id="name" type="text" name="name" class="form-control">
                            <small class="form-text text-muted"></small>
                        </div>
                        <div class="form-group">
                            <label>年龄</label>
                            <input id="age" type="number" name="age" class="form-control">
                            <small class="form-text text-muted"></small>
                        </div>

                        <div class="form-group">
                            <label>部门</label>

                            <select id="dept" name="did" class="form-control">


                            </select>

                            <small class="form-text text-muted"></small>
                        </div>



                    </form>
                </div>
            </div>

        </div>


        <div class="submit-box">
            <button type="button" onclick="sub()" class="btn btn-primary">确定提交</button>
            <button type="button" onclick="window.history.back()" class="btn btn-outline-secondary">取消</button>
        </div>
    </div>
</main>



        </div>

    </main>
</div>

</body>
<SCRIPT>
    $(function () {
        var id = (window.location.href).split('?')[1];

        var did ='';
        $.ajax({
            type:"post",
            url:"user/one",
            data:{"id":id},
            dataType:"json",
            ansyc:false,
            success:function (data) {
                var did ="";
                if(data.user != null) {
                    $("#name").val(data.user.name);
                    $("#age").val(data.user.age);
                    $("#id").val(data.user.id);
                    did =data.user.did;

                }
                 $("#dept").empty();
                var ht = '';
                $.each(data.list,function (i,v) {
                    var c ='';
                    if(v.id ==did ){c ='selected=true'};

                    ht = ht + '<option '+c+' value="'+v.id+'">'+v.dname+'</option>';
                });
                $("#dept").append(ht);
            }

        });

/*
        $.ajax({
            type:"post",
            url:"user/dept",
            dataType:"json",
            success:function (data) {

            }

        });*/
    })
    //var name=$("#name").val()
    //var age=$("#age").val()
    function sub() {
        $.ajax({
            type:"post",
            url:"user/add",
            data:$("#form").serialize(),//{'name':name，‘age’:age}
            success:function () {
               window.location.href="user_index.html";
            }

        });
    }
</SCRIPT>
</html>
